<template>
	<view class="container">
		<Header>
			{{ title }}
		</Header>
		<view class="content article">
			<view class="title">
				{{data.title}}
			</view>
			<view class="date">
				<span>{{data.createtime}}</span>
				<!-- <span>来源：新华网</span> -->
			</view>
			<!-- <view v-html="data.content"></view> -->
			<mp-html :content="data.content" />
		</view>
		<div class="btns">
			<button class="btn" disabled v-if="data.isjoin == 2">已参加</button>
			<button type="primary" class="btn delete" @click="onSubmit()" v-else>参加活动</button>
		</div>
	</view>
</template>

<script>
	import Header from '../../components/header.vue'
	import request from '../../common/request.js'
	export default {
		components: {
			Header
		},
		data() {
			return {
				id: '',
				data:{},
				title: ''
			}
		},
		onLoad(option) {
			this.id  = option.id
			this.title = option.title
		},
		mounted(){
			this.getDetailData()
		},
		methods: {
			getDetailData(){
				request({
					url:'/sxzx/detail',
					data:{
						new_id: this.id
					},
					method: 'POST'
				}).then(res => {
					if(res.code == 1){
						this.data = res.data
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			onSubmit(){
				request({
					url:'/sxzx/joinact',
					data:{
						new_id: this.id
					},
					method: 'POST'
				}).then(res => {
					if(res.code == 1){
						this.data.isjoin = 2
						uni.showToast({
							title: '已参加活动',
							icon: 'none',
							duration: 2000
						});
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			}
		}
	}
</script>

<style scoped>
	.container{
		/* background-color: #f9f9f9;
		min-height: calc(100vh - 45px); */
	}
	.content{
		padding: 20px;
		line-height: 30px;
	}
	.title{
		font-size: 16px;
		font-weight: bold;
		text-align: center;
		line-height: 26px;
	}
	.date{
		font-size: 14px;
		text-align: center;
		margin: 15px 0px;
	}
	.date span{
		margin: 0px 10px;
	}
	.btns{
		background-color: #fff;
		position: fixed;
		bottom: 0px;
		width: 100%;
		padding: 10px;
		box-sizing: border-box;
	}
</style>